package com.zhou.cloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.zhou.cloud.dao.entity.Dept;
import com.zhou.cloud.service.IDeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhouyongjun
 * @Description:
 * @date 2021/4/6 16:45
 */
@RestController
@RequestMapping("dept")
@Slf4j
public class DeptController {
    @Autowired
    IDeptService deptService;
    @GetMapping("/get/{id}")
    public Dept get(@PathVariable("id") Integer id) {
        Dept dept = deptService.get(id);
        System.out.println(dept);
        return dept;

    }
    @PostMapping("/add")
    public boolean add(Dept dept) {
        return deptService.add(dept);
    }

    @DeleteMapping("del/{id}")
    public boolean delete(@PathVariable("id") Long id) {
        return false;
    }

    @GetMapping("/list")
    @SentinelResource(value = "provider-list",fallback = "listFallback",blockHandler = "listFallback")
    public List<Dept> list() {
        List<Dept> list = deptService.getAll();
        System.out.println(list);
        return list;
    }
    @GetMapping("/list/page")
    @SentinelResource(value = "provider-list",fallback = "listFallback",blockHandler = "listFallback")
    public List<Dept> pageList(int page,int pageNum) {
        List<Dept> list = deptService.getListByPage(page,pageNum);
        System.out.println(list);
        return list;
    }
    public List<Dept> listFallback(Exception e){
        String msg = "listfallback ...";
        log.warn("<<<<fallback");
        log.error("",e);
        return null;
    }

}
